/*
* Copyright 2016 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-dealerApp-open-api
*
* @File name : DealerAppHomePageController.java
*
* @Author : WangHuicheng
*
* @Date : 2016年11月21日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2016年11月21日    WangHuicheng    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmmc.dealerApp.api.controller;

import java.util.HashMap;
import java.util.Map;

import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.marketing.common.constants.ResultMsgConstants;
import org.marketing.common.dto.search.DealerAppSearchDto;
import org.marketing.common.dto.testdrivingAm.TestDrivingRoutesDto;
import org.marketing.common.dto.testdrivingAm.TestdrivingAmFrecordDto;
import org.marketing.common.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.gmmc.dealerApp.api.constant.DealerAppConstant;
import com.yonyou.gmmc.dealerApp.api.service.CallTestDrivingService;

/**
* DealerApp用户试乘试驾信息
* @author WangHuicheng

* @date 2016年11月21日
*/
@RestController
@RequestMapping(value = DealerAppConstant.BASE_PATH+"/testDriver")
public class DealerAppTestDriverController {
    private Logger  logger = Logger.getLogger(DealerAppTestDriverController.class);

    
    @Autowired
    private CallTestDrivingService callTestDriverServiceInterface;
    
    @RequestMapping(value="/getTestDriverInfoList",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object>getTestDriverInfoList(@RequestBody DealerAppSearchDto dealerAppSearchDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            if (null != dealerAppSearchDto.getStartDateEnd()){
                dealerAppSearchDto.setStartDateEnd(DateUtil.addDay(dealerAppSearchDto.getStartDateEnd(),1));
            }
            if (null != dealerAppSearchDto.getSubmitDateEnd()){
                dealerAppSearchDto.setSubmitDateEnd(DateUtil.addDay(dealerAppSearchDto.getSubmitDateEnd(),1));
            }
            result = callTestDriverServiceInterface.getTestDriverInfoList(dealerAppSearchDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
    *
    * @author WangHuicheng
    * 保存试驾预约跟进记录
    * @date 2016年11月21日
    * @param testDrivingAmDto
    * @return
    * @throws Exception
    */
    @RequestMapping(value = "/saveFollowRecords", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody Map<String, Object> saveTestDrivingAppointFrecord(@RequestBody @Valid TestdrivingAmFrecordDto testdrivingAmFrecordDto) {
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callTestDriverServiceInterface.saveTestDrivingAppointFrecord(testdrivingAmFrecordDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
        
    }

    
    /**
    *
    * @author LiuJun
    * 更新试驾预约状态
    * @date 2016年11月21日
    * @param testdrivingAmFrecordDto
    * @return
    * @throws Exception
    */
    @RequestMapping(value = "/updateStatus",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object> updateTestDrivingAppointStatus(@RequestBody @Valid TestdrivingAmFrecordDto testdrivingAmFrecordDto) {
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callTestDriverServiceInterface.updateTestDrivingAppointStatus(testdrivingAmFrecordDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    
    /**
     * 试驾线路
     * 
     * @author WangHuicheng
     * @date 2016年11月30日
     * @param testDrivingRoutesDto
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getTestDriverRoutes", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> getTestDriverRoutes(@RequestBody TestDrivingRoutesDto testDrivingRoutesDto) throws Exception {
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callTestDriverServiceInterface.getTestDriverRoutes(testDrivingRoutesDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
}
